package com.example.testone

import android.content.res.Configuration
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.view.Gravity
import android.view.View
import android.widget.Button
import com.example.testone.uiComponents.WordsBubble
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

class MainActivity2 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        Log.d("GaoChang", "主线程id：${mainLooper.thread.id}")
        //test()
        //Log.d("GaoChang", "执行结束：")

        //launch不会阻断主线程
        val job = GlobalScope.launch {
            delay(1000)
            Log.d("GaoChang", "携程id：${Thread.currentThread().id}")
        }
        val d = Log.d("GaoChang", "执行结束：")

        val btn = findViewById<Button>(R.id.btn_bubble)
        btn.setOnClickListener(View.OnClickListener {
            WordsBubble(this)
                .text("测试测试测试测试测试测试测试测试测试")
                .gravity(Gravity.LEFT or Gravity.TOP)
                .with(it)
                .show()
        })

    }
    //阻舍
    private fun test() = runBlocking {
        repeat(8) {
            Log.d("GaoChang", "携程id：${Thread.currentThread().id}")
            delay(1_000)
        }
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        Log.d("GaoChang", "onConfigurationChanged: ")
        val mode = this.resources.configuration.uiMode
        Log.d("GaoChang", "mode: $mode")
        when(mode){
            Configuration.UI_MODE_NIGHT_YES->
                Log.d("GaoChang", "黑暗主题: ")
        }
    }

    fun BtnClick(view: View) {
        //val wordsBubble = WordsBubble(this)
//        WordsBubble(this)
//            .text("测试测试测试测试测试测试测试测试测试")
//            .gravity(Gravity.LEFT or Gravity.TOP)
//            .with(view)
//            .show()
        WordsBubbleTry().show(view,this)
    }
}